import {
  Column,
  CreateDateColumn,
  Entity,
  OneToMany,
  PrimaryGeneratedColumn,
  UpdateDateColumn,
} from 'typeorm';
import { MovieModuleType } from '../types/movieModule';
import { MovieDownloadEntity } from './movieDownload.entity';


// 电影和下载链接是一对多的关系 ?
@Entity('movie')
export class MovieEntity {
  @PrimaryGeneratedColumn({ type: 'int' })
  id: number;

  @Column({ type: 'varchar'})
  title: string;

  @Column({ type: 'varchar', nullable: true })
  cover: string;

  @Column({ type: 'longtext', nullable: true })
  resourceUrl: string;

  @Column({ type: 'longtext', nullable: true }) 
  introduction: string;

  @Column({ type: 'longtext', nullable: true })  
  publisthTime: string;

  @Column({ type: 'longtext', nullable: true })
  movieName: string;

  @Column({ type: 'longtext', nullable: true })  
  country: string;

  @Column({ type: 'longtext', nullable: true })
  category: string;

  @Column({ type: 'longtext', nullable: true })
  language: string;

  @Column({ type: 'longtext', nullable: true })
  releaseDate: string;

  @Column({ type: 'longtext', nullable: true })
  movieLength: string;

  @Column({ type: 'longtext', nullable: true })
  director: string;

  @Column({ type: 'longtext', nullable: true })
  actors: string;

  // 电影模块是枚举类型
  @Column({ type: 'enum', enum: MovieModuleType })
  movieModuleType: MovieModuleType;

 
  @CreateDateColumn()
  createdAt: Date;

  @UpdateDateColumn()
  updatedAt: Date;

  // 下载地址是一对多的关系
  @OneToMany(() => MovieDownloadEntity, (download) => download.movie, {
    cascade: true, // 启用级联保存
  })
  downloadUrls: MovieDownloadEntity[];
}
